﻿using ConsoleApplication2.Entity;
using ConsoleApplication2.pushApi;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2.Dao
{
    public class T_MsgCmd
    {
        public static void sendNewMsg()
        {
            String time = DateTime.Now.ToString("yyyy-MM-dd");
            String sql = String.Format("select id,Title,Content from [T_Msg] where IsSended=0 and IsDel=0 and IsUsed=1 and SendTime='{0}'", time);
            DataTable dt = SQLHelper.GetTable(sql);
            foreach(DataRow dr in dt.Rows)
            {

                MessagePara par = new MessagePara();
                par.Title = dr[1].ToString();
                par.MessageId = Convert.ToInt32(dr[0].ToString());
                par.MessageType =3;
                String json = JsonHelper.SerializeObject(par);
                string url = HttpAddress.all;
                HttpClientHelp.sendMessage(url, json);

                sql = String.Format("update  [T_Msg] set  IsSended=1 where id='{0}'",dr[0]);
                SQLHelper.ExcuteSQL(sql);
            }
        }
    }
}
